﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace JQMergeFramework
{
    public class UIReceivePropTips : MonoBehaviour
    {

        public UISwitchChild iconSwitchChild;
        public Text propNameTxt,propDesTxt;
        public Text limitTipsTxt,limitNumTxt;
        private int mItemId;
        private void Awake()
        {
            UIManager.Instance.AddBtnListener(this.transform);
        }

        void OnBtnClick(Transform trans)
        {

            AudioManager.Instance.Play(AudioName.Click);


            if (InputManager.I.isNoRayClick)
            {
                return;
            }

            switch (trans.name)
            {
                case "BtnClose":
                    Close();
                    break;
                case "BtnReceive":
                    if (mItemId == PropId.RemoveProp)
                    {
                        DataManager.Instance.SetPropNum(mItemId,2);
                    }
                    else
                    {
                        DataManager.Instance.SetPropNum(mItemId,1);
                    }
                    
                    DataManager.Instance.SetPropDayUseNum(mItemId);
                    Close();
                    break;
            }
        }


        public void Open(int id)
        {
            mItemId = id;
            GetComponent<UIPopAnimate>().PopStart();

            DataManager dataManager = DataManager.Instance;
            
            switch (id)
            {
                case  PropId.DiscardProp:
                    propNameTxt.text = "丢弃";
                    propDesTxt.text = "可以将预放置区第一个建筑丢弃!";
                    iconSwitchChild.index = 3;
                    break;
                case  PropId.MoveProp:
                    propNameTxt.text = "移动";
                    propDesTxt.text = "选择一个建筑，可以移动或交换位置!";
                    iconSwitchChild.index = 1;
                    break;
                case  PropId.RefreshProp:
                    propNameTxt.text = "刷新";
                    propDesTxt.text = "刷新预放置区的所有建筑";
                    iconSwitchChild.index = 0;
                    break;
                case  PropId.RemoveProp:
                    propNameTxt.text = "删除";
                    propNameTxt.text = "选择棋盘上的一个建筑删除！";
                    iconSwitchChild.index = 2;
                    break;
            }
            
            limitNumTxt.text = string.Format("已获取次数：{0}",dataManager.GetPropDayUseNum(id));
            limitTipsTxt.text = string.Format("注：该道具每天只能获取{0}次", GameCfg.LimitDayUsePropNum);
        }

        void Close()
        {
            GetComponent<UIPopAnimate>().PopEnd();
        }

    }
}